<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-4-2
  Time: 上午9:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加数据</title>
    <script>
        $(function () {
            $.ajax({
                url: '/area/provinceList',
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    $("#provinces").html(data);
                }
            });
            $.ajax({
                url: '/area/cityList',
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    $("#cities").html(data);
                }
            });


            $("#provinceBtn").click(function () {
                var s = $("#province").val();
                $.ajax({
                    url: '/area/addProvince/' + s,
                    type: 'GET',
                    dataType: 'text',
                    success: function () {
                        $.ajax({
                            url: '/area/provinceList',
                            type: 'GET',
                            dataType: 'json',
                            success: function (data) {
                                $("#provinces").html(data);
                            }
                        })
                    }
                })
            });

            $("#cityBtn").click(function () {
                var p = $("#provinces").val();
                var city = $("#city").val();
                $.ajax({
                    url: '/area/addCity/' + p + "/" + city,
                    type: 'GET',
                    dataType: 'text',
                    success: function () {
                        $.ajax({
                            url: '/area/cityList',
                            type: 'GET',
                            dataType: 'json',
                            success: function (data) {
                                $("#cities").html(data);
                            }
                        })
                    }
                })
            });

            $("#districtBtn").click(function () {
                var c = $("#cities").val();
                var district = $("#district").val();
                $.ajax({
                    url: '/area/addDistrict/' + c + "/" + district,
                    type: 'GET'
                })
            });


        })
    </script>
</head>
<body>
<div>
    <div id="provinceDiv">
        <input type="text" id="province"/>&nbsp;
        <input type="button" id="provinceBtn" value="添加省"/>
    </div>

    <div id="cityDiv">
        所属省：<select id="provinces">
    </select>&nbsp;
        所在市：<input type="text" id="city"/>&nbsp;<input type="button" id="cityBtn" value="添加市">
    </div>

    <div id="districtDiv">
        所属市：<select id="cities">
    </select>&nbsp;
        所在区：<input type="text" id="district"/>&nbsp;<input type="button" id="districtBtn" value="添加区">
    </div>
</div>
<div>

</div>
</body>
</html>